/*
*	Authored by Phill Gibson
*	Name: linked list execise
*	Purpose:
*
*		1 create linked list and display
*		2 add new node
*		3 find and delete a node
*
*	using POINTERS
**/

#include<stdlib.h>
#include<stdio.h>
#include<string.h>

//#include "stdafx.h"
#include <tchar.h>
#include <windows.h>



// struct item{
	// int val;
	// struct item *next; //!important. declares next to be a pointer to a list_el,
// };	 					  //  not an list_el itself

struct list_el{
	int val;
	struct list_el *next;
};

typedef struct list_el item; 




#include"functions.h"
#include"mergeSort.h"



void main()
{
	item* curr;
	item *head;
	int length=0;
	int i;
	int option;

	 head= NULL;
	 
	for(i=1;i<=5;i++)
	{
		curr = (item*) malloc(sizeof(item));		
		curr->val = (rand() % 99 + 1);
		curr->next = head;		
		head = curr;
		length++;
	}

	
	printf("1) add new Node\n2) Delete Node\n3) Print List\n4) Get list length\n5) Sort\nEnter option or 9 to exit: ");
	scanf("%d%*c",&option);
	while(option !=9)
	{
		switch(option)
		{
		case 1:
			addNode(&head);
			length++;
			break;
		case 2:
			deleteNode(&head);
			break;
		case 3:
			printList(head);
			break;
		case 4:
			printf("\nList Length is: %d\n\n",length);
			break;
		case 5:
			float time;
			__int64 ctr1 = 0, ctr2 = 0, freq = 0;
			int acc = 0, i = 0;
			if (QueryPerformanceCounter((LARGE_INTEGER *)&ctr1)!= 0)
			{
				MergeSort(&head);
						// Finish timing the code.
				QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);

				QueryPerformanceFrequency((LARGE_INTEGER *)&freq);

		
				time = (ctr2 - ctr1) * 1.0 / freq;

				printf("\nFrequency: %d\n", freq);
				printf("Time: %f\n\n", time);
				//system("pause");
				printf("\n");

			}
			else
			{
				DWORD dwError = GetLastError();
			}
				//printList(head);
			break;
		}

		printf("1) add new Node\n2) Delete Node\n3) Print List\n4) Get list length\n5) Sort\nEnter option or 9 to exit: ");
		scanf("%d%*c",&option);
	 }


}






